package com.longshihan.ast;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;

import java.io.File;
import java.lang.reflect.Parameter;
import java.nio.charset.Charset;

public class AstMain {
    private static  String FILE_PATH = "ReversePolishNotation.java";
    public static void main(String[] args) throws Exception{
        JavaParser javaParser=new JavaParser();
        String path=System.getProperty("user.dir");
        FILE_PATH=path+"/src/main/java/com/longshihan/ast/MainActivity.java";
        ParseResult<CompilationUnit> parseResult = javaParser.parse(new File(FILE_PATH),
                Charset.defaultCharset());
        CompilationUnit compilationUnit=parseResult.getResult().get();
        new MethodChangerVisitor().visit(compilationUnit, null);
        System.out.println("");
    }
    private static class MethodChangerVisitor extends VoidVisitorAdapter {

        @Override
        public void visit(MethodDeclaration n, Object arg) {
            // change the name of the method to upper case
            n.setName(n.getName());

            // create the new parameter
//            Parameter newArg = ASTHelper.createParameter(ASTHelper.INT_TYPE, "value");

            // add the parameter to the method
//            ASTHelper.addParameter(n, newArg);
        }

    }
}
